/*
 * mqsend.cpp
 *
 *  Created on: Jul 12, 2013
 *      Author: m
 */

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "MyMessage.h"
#include "MessageQueue.h"

#define TEST_MTYPE 1

using namespace ipc;

int main ( int argc, char* argv[] )
{
    char mostrar[10240];
    MyMessage msg;

    MessageQueue<MyMessage> mq = MessageQueue<MyMessage>::get( "/tmp/mychannel", 'h' );

    do
    {
        sprintf( mostrar,
                "MQSND: "
                "Ingrese mtype y luego dato (un char)\n" );
        write( fileno(stdout), mostrar, strlen(mostrar) );

        std::cin >> msg.mtype;
        std::cin >> msg.c;

        sprintf( mostrar,
                "MQSND: "
                "Enviando mensaje: mtype(%ld) data(%c)\n",
                msg.mtype, msg.c );
        write( fileno(stdout), mostrar, strlen(mostrar) );

        mq.put( TEST_MTYPE, msg );

    } while ( msg.c != 'q' );

    return 0;
}
